package controller.admin;

import service.TypeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 管理员界面类目添加
 */
@WebServlet(name = "AdminTypeAddServlet", value = "/admin/type_add")
public class AdminTypeAddServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TypeService ts = new TypeService();
        String typeName = request.getParameter("name");
        boolean flag = ts.addType(typeName);
        if (flag)
            request.setAttribute("msg", "添加成功！");
        else
            request.setAttribute("failMsg", "添加失败！");
        request.getRequestDispatcher("type_list").forward(request, response);
    }
}
